package cn.itcast.jdbc;

import java.sql.*;
import java.util.Scanner;

public class jdbcDemo04 {
    public static void main(String[] args) throws SQLException {

        // 用户输入用户名和密码，判断是否能够登录
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String username = scanner.nextLine();
        System.out.println("请输入密码：");
        String password = scanner.nextLine();


        // 获取连接
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb16_jdbc", "root", "my123456");
        //执行SQL
        Statement statement = connection.createStatement();
        String sql = "select * from user where username = '"+username+"' and password = '"+password+"'";
        System.out.println(sql);
        ResultSet resultSet = statement.executeQuery(sql);

        if (resultSet.next()){
            System.out.println("登陆成功");

        }else{
            System.out.println("登陆失败");
        }

        //关闭连接
        resultSet.close();
        statement.close();
        connection.close();

    }
}
